package VendingMachine;

import java.io.*;

public abstract class VendingMachine {

    public static void main(String[] args) throws WrongStateException {

        VendingMachine vm = AUVendingMachine.getInstance();
        vm.pay();
        vm.makingChange();
        vm.cooking();
        vm.finishCooking();
        vm.DisplayState();
    }
    protected VendingMachineState state = new IdelState(this);
    protected int color;
//	protected static VendingMachine vm = null;

    public String getColor(String country) throws FileNotFoundException {
        try {
            FileInputStream fstream = new FileInputStream("country.data");
            
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            
            while ((strLine = br.readLine()) != null) {
                
                String[] temp = strLine.split(" ");
                temp[1]
                new java.awt.Color(0, 102, 153);
            }
            
            in.close();
        } catch (Exception e) {//Catch exception if any
            return null;
        }
    }

    public String DisplayState() {
        return this.state.getClass().getSimpleName();
    }

    public void setState(VendingMachineState state) {
        this.state = state;
    }

    public void pay() throws WrongStateException {

        state.pay();
    }

    public void finishPay() throws WrongStateException {

        state.finishPay();
    }

    public void makingChange() throws WrongStateException {
        state.makingChange();
    }

    public void cooking() throws WrongStateException {

        state.cooking();

    }

    public void finishCooking() throws WrongStateException {

        state.finishCooking();
    }
}

/**
 * ***************************end of machine***************************
 */
abstract class VendingMachineState {

    protected VendingMachine vm;

    abstract public void pay() throws WrongStateException;

    abstract public void finishPay() throws WrongStateException;

    abstract public void cooking() throws WrongStateException;

    abstract public void finishCooking() throws WrongStateException;

    abstract public void makingChange() throws WrongStateException;
}

class IdelState extends VendingMachineState {

    public IdelState(VendingMachine vm) {
        this.vm = vm;
    }

    public void pay() {
        System.out.println("paying");
        vm.setState(new MakingChangeState(vm));
    }

    public void finishPay() throws WrongStateException {

        throw new WrongStateException();
    }

    public void makingChange() throws WrongStateException {

        throw new WrongStateException();
    }

    public void cooking() throws WrongStateException {

        throw new WrongStateException();
    }

    public void finishCooking() throws WrongStateException {
        throw new WrongStateException();
    }
}

class MakingChangeState extends VendingMachineState {

    public MakingChangeState(VendingMachine vm) {
        this.vm = vm;
    }

    public void pay() throws WrongStateException {
        throw new WrongStateException();
    }

    public void finishPay() throws WrongStateException {

        throw new WrongStateException();
    }

    public void makingChange() {
        System.out.println("Making change");
        vm.setState(new CookingState(vm));
    }

    public void cooking() throws WrongStateException {

        throw new WrongStateException();

    }

    public void finishCooking() throws WrongStateException {
        throw new WrongStateException();
    }
}

class CookingState extends VendingMachineState {

    public CookingState(VendingMachine vm) {
        this.vm = vm;
    }

    public void pay() throws WrongStateException {
        throw new WrongStateException();
    }

    public void finishPay() throws WrongStateException {

        throw new WrongStateException();
    }

    public void makingChange() throws WrongStateException {
        throw new WrongStateException();
    }

    public void cooking() {

        System.out.println("Cooking...");
        vm.setState(new CookedState(vm));

    }

    public void finishCooking() throws WrongStateException {
        throw new WrongStateException();
    }
}

class CookedState extends VendingMachineState {

    public CookedState(VendingMachine vm) {
        this.vm = vm;
    }

    public void pay() throws WrongStateException {
        throw new WrongStateException();
    }

    public void finishPay() throws WrongStateException {

        throw new WrongStateException();
    }

    public void makingChange() throws WrongStateException {
        throw new WrongStateException();
    }

    public void cooking() throws WrongStateException {

        throw new WrongStateException();

    }

    public void finishCooking() {
        System.out.println("Finished cooking");
        vm.setState(new IdelState(vm));
    }
}

/*
 * class PayingState extends VendingMachineState{
 *
 *
 * public PayingState(VendingMachine vm){ this.vm = vm; }
 *
 * public void pay() throws WrongStateException{ throw new
 * WrongStateException(); }
 *
 * public void finishPay(){
 *
 * System.out.println("Paying..."); vm.setState(new MakingChangeState(vm)); }
 *
 * public void makingChange()throws WrongStateException{ throw new
 * WrongStateException(); }
 *
 *
 * public void cooking()throws WrongStateException{
 *
 * throw new WrongStateException();
 *
 * }
 *
 * public void finishCooking()throws WrongStateException{
 *
 * throw new WrongStateException();
 *
 * }
 *
 * }
 */
class WrongStateException extends Exception {
};
